#This script will summarize the matched datasets used in Hazards or Hassles. This
#provides the information necessary to replicate/verify the balance statistics
#reported in Tables 1-3.

#users will need to install the foreign and MatchIt packages:
# install.packages("MatchIt")
# library(MatchIt)

#first, import the data for matching:
setwd("D:/Projects/FallingOutofFavor/FOOF P(Fail)/PSRMRnR/Replication/Data")  #set to proper directory

RnR_Dems <- read.delim("RnR_PfailSampleDems.txt")
RnR_Anos <- read.delim("RnR_PfailSampleAnos.txt")
RnR_AUTS <- read.delim("RnR_PfailSampleJustAuts.txt")

#Read as a data frames:

RnR_Dems<-as.data.frame(RnR_Dems)   
RnR_Anos<-as.data.frame(RnR_Anos) 
RnR_AUTS<-as.data.frame(RnR_AUTS)     

#MatchIt commands for MID, Lxb, and interaction:
Dems_3sub <-matchit(target~Lxb + MIDtopsanctionerever+Lxb*MIDtopsanctionerever,
                    data=RnR_Dems, method="nearest", subclass=3)

Anos_5sub <-matchit(target~Lxb + MIDtopsanctionerever + Lxb*MIDtopsanctionerever,
                    method="nearest", subclass=5, data=RnR_Anos)

AUTS_sub <-matchit(target~Lxb + MIDtopsanctionerever + Lxb*MIDtopsanctionerever,
                   method="subclass", data=RnR_AUTS)

#MatchIt commands for Ally index, Lxb, and interaction:
Dems_subAlly <-matchit(target~ Lxb + defenseweight + defenseweight*Lxb , data=RnR_Dems, 
                       method="nearest", subclass=3)

Autos_subAlly<-matchit(target~Lxb + defenseweight + defenseweight*Lxb,
                       data=RnR_AUTS, method="subclass")


Anos_subAlly<-matchit(target~Lxb + defenseweight + defenseweight*Lxb,
                      data=RnR_Anos, method="subclass")

#MatchIt commands for just lXb
Dems_subXB <-matchit(target~Lxb, data=RnR_Dems, method="subclass")

Anos_subXb<-matchit(target~Lxb, data=RnR_Anos, method="subclass")

Autos_subXb<-matchit(target~Lxb, data=RnR_AUTS, method="subclass")



#Table 1:
Dems_3sub
summary(Dems_3sub)

Dems_subAlly
summary(Dems_subAlly)

Dems_subXB
summary(Dems_subXB)

#Table 2:
AUTS_sub 
summary(AUTS_sub)

Autos_subAlly
summary(Autos_subAlly)

Autos_subXb
summary(Autos_subXb)

#Table 3:
Anos_5sub
summary(Anos_5sub)

Anos_subAlly
summary(Anos_subAlly)

Anos_subXb
summary(Anos_subXb)

